﻿using System;
using System.Net;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Data;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.ComponentModel;
using Islamic_influence_in_Venetian_cuture.LangResources;

namespace Islamic_influence_in_Venetian_cuture
{
    public static class ExtensionMethods
    {
        public static ObservableCollection<T> ToObservableCollection<T>(this IEnumerable<T> coll)// where T : INotifyPropertyChanged
        {
            var res = new ObservableCollection<T>();
            foreach (var item in coll)
            {
                res.Add(item);
            }
            return res;
        }
        public static string reverse(this string str)
        {
            var parts = str.Split(new char[] { ';' });
            if (parts.Length > 1)
            {
                var text = (from part in parts select reverseNoSemicolon(part)).Aggregate("", (acc, part) => acc + ';' + part);
                return text;
            }
            return reverseNoSemicolon(str);
        }

        public static string ToFirstUpper(this string str)
        {
            var first = ("" + str.First()).ToUpper();
            return first + str.Substring(1);
            
        }

        #region Private methods
        private static string reverseNoSemicolon(string str)
        {
            var words = str.Split(new char[] { ' ' });
            var text = (from w in words select w.Aggregate("", (acc, ch) => ch.analyze() + acc)).Aggregate("", (acc, word) => acc + " " + word);
            return text;
        }
        private static char analyze(this char ch)
        {
            switch (ch)
            {
                //case '(':
                //    return ' ';
                //case ')':
                //    return ' ';
                default:
                    return ch;
            }
        }
        #endregion
    }
    public class TextAlignmentConverter : IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return Lang.CurrentCulture == Cultures.Arabic || Lang.CurrentCulture == Cultures.Persian ? TextAlignment.Right : TextAlignment.Left;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    //public class ArabicReverseConverter : IValueConverter
    //{

    //    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    //    {
    //        if (Lang.CurrentCulture == Cultures.Arabic || Lang.CurrentCulture == Cultures.Persian)
    //        {
    //            return (value as string).reverse();
    //        }
    //        return value;
    //    }

    //    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    //    {
    //        throw new NotImplementedException();
    //    }
    //}
}
